<?php

namespace app\command;

use app\admin\model\Config;
use app\model\Talent;
use app\model\User;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\facade\Log;
use util\Logger;
use Wechat\CommerceApp;

class ResetUserAiCountCommand extends Command
{
    protected function configure()
    {
        $this->setName('reset-user-ai')
            ->setDescription('每天重置用户AI次数');
    }

    protected function execute(Input $input, Output $output)
    {
        try {
            $ai_count = Config::where('name', 'ai_day')->value('value');
            if ($ai_count) {
                $ai_count = intval($ai_count);
                User::field('id')->chunk(100, (function ($users) use ($ai_count) {
                    foreach ($users as $user) {
                        $user->chat_count = $ai_count;
                        $user->save();
                    }
                }));
            }
        } catch (\Exception $e) {
            Logger::error($e->getMessage());
            exit;
        }

    }
}
